package src.main.java.org.exception;

public class ExceptionTest {
    public static void main(String[] args) {
        try {
            saveAge(160);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void saveAge(int age){
        if(age>0 && age<150){
            System.out.println("年龄被成功保存："+age);
        }else {
            //抛出异常对象，运行时异常
            throw new AgeIllegalRuntimeException("/age is illegal,your age is "+age);
        }
    }
    public static void saveAge2(int age) throws AgeIllegalException{
        if(age>0 && age<150){
            System.out.println("年龄被成功保存："+age);
        }else {
            //抛出异常对象,编译时异常
            throw new AgeIllegalException("/age is illegal,your age is "+age);
        }
    }
}
